"""FullScreen

This file explores various ways to toggle into fullscreen mode
"""

import wx

from operator import or_

TBFLAGS = ( wx.TB_HORIZONTAL
            | wx.NO_BORDER
            | wx.TB_FLAT
            #| wx.TB_TEXT
            #| wx.TB_HORZ_LAYOUT
            )

class FullScreenTestPanel(wx.Panel):
    def __init__(self,parent):
        wx.Panel.__init__(self,parent,name="fullscreentestpanel")
        self.SetBackgroundColour('white')

        FlagList = ['FULLSCREEN_NOMENUBAR',
                    'FULLSCREEN_NOTOOLBAR',
                    'FULLSCREEN_NOSTATUSBAR',
                    'FULLSCREEN_NOBORDER',
                    'FULLSCREEN_NOCAPTION',
                    'FULLSCREEN_ALL']

        lb = wx.CheckListBox(self,choices=FlagList)
        self.lb = lb
        self.FullScreenBtn = wx.Button(self,label="Go to Full Screen")
        self.FullScreenBtn.Bind(wx.EVT_BUTTON,self.FullScreen)

        sizer = wx.StaticBoxSizer(wx.StaticBox(self,label="Full Screen"),
                                  wx.VERTICAL)
        sizer.Add(lb)
        sizer.Add(self.FullScreenBtn)
        self.SetSizer(sizer)
        self.Layout()

    def GetFlags(self):
        """Returns the flags selected in the box"""
        res = []
        for x in range(self.lb.GetCount()):
            if self.lb.IsChecked(x):
                val = self.lb.GetString(x)
                res.append(getattr(wx,val))
        return reduce(or_,res,0)

    def FullScreen(self,evt):
        top = self.GetTopLevelParent()
        top.OnFullScreen(evt)

class TestFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, wx.ID_ANY, 'Test FullScreen', size=(600, 400))

        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

        self.client = FullScreenTestPanel(self)

        ### Create the toolbar
        tb = self.CreateToolBar( TBFLAGS )

        ### Create the Menubar
        mbar = wx.MenuBar()
        the_menu = wx.Menu()
        fullscreenMI = the_menu.Append(wx.ID_ANY,"Full Screen\tF12","Toggles Full Screen Mode")
        mbar.Append(the_menu,"Stuff")

        self.SetMenuBar(mbar)

        ### Bind full menu stuff
        self.Bind(wx.EVT_MENU,self.OnFullScreen,id=fullscreenMI.GetId())

        self.CreateStatusBar()

        tsize = (24,24)
        new_bmp =  wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tsize)
        open_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize)
        copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize)
        paste_bmp= wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR, tsize)

        tb.SetToolBitmapSize(tsize)

        tb.AddLabelTool(10, "New", new_bmp, shortHelp="New", longHelp="Long help for 'New'")
        tb.AddLabelTool(20, "Open", open_bmp, shortHelp="Open", longHelp="Long help for 'Open'")

        tb.AddSeparator()
        tb.AddSimpleTool(30, copy_bmp, "Copy", "Long help for 'Copy'")
        tb.AddSimpleTool(40, paste_bmp, "Paste", "Long help for 'Paste'")
        tb.Realize()

    def OnCloseWindow(self, event):
        self.Destroy()

    def OnFullScreen(self,event):
        flags = self.client.GetFlags()
        self.ShowFullScreen(not self.IsFullScreen(),flags)

class TestApp(wx.App):
    def OnInit(self):

        self.main = TestFrame(None)
        self.main.Show()
        self.SetTopWindow(self.main)
        return True

def main():
    application = TestApp(redirect=False)
    application.MainLoop()

if __name__=='__main__':
    main()
